package cn.sdc.bugKiller.web;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import cn.sdc.bugKiller.RequestContants;
import cn.sdc.bugKiller.bean.BugDealResult;
import cn.sdc.bugKiller.bean.BugStatus;
import cn.sdc.bugKiller.bean.PriorityBean;
import cn.sdc.bugKiller.service.BugDealService;
import cn.sdc.bugKiller.service.CodeDealService;
import cn.sdc.sfw.util.StringUtil;

public class DropdownMaps implements RequestContants{
	
	private static BugDealService service = new BugDealService();
	private static CodeDealService codeService = new CodeDealService();
	
	//HashMap for dropdown list
	private static HashMap moduleMap = new HashMap<Integer, String>();
	private static HashMap programMap = new HashMap<Integer, String>();
	private static HashMap statusMap = new HashMap<Integer, String>();
	private static HashMap priorityMap = new HashMap<Integer, String>();
	private static HashMap assignerMap = new HashMap<Integer, String>();
	private static HashMap handlerMap = new HashMap<Integer, String>();
	private static HashMap categroyMap = new HashMap<Integer, String>();
	private static HashMap dealResultMap = new HashMap<Integer, String>();
	
	static{
		moduleMap.putAll(codeService.getModuleMap());
		
		programMap.putAll(codeService.getProgramMap());
		
		statusMap.putAll(BugStatus.statusMap);
		
		priorityMap.putAll(PriorityBean.priotiryMap);
		
		assignerMap.putAll(codeService.getMemberMap());
		
		handlerMap.putAll(codeService.getMemberMap());

		categroyMap.putAll(codeService.getBugCategoryMap());
	}
	
	public static void setDropdownMap(HttpServletRequest req){
		setDropdownMap(req,true);
	}
	
	public static void setDropdownMapBlank(HttpServletRequest req){
		setDropdownMap(req,false);
	}
	
	private static void setDropdownMap(HttpServletRequest req, boolean needAll){
		if(!needAll){
			moduleMap.put(DROPDOWN_ALL_KEY, StringUtil.EMPTY_STRING);
			programMap.put(DROPDOWN_ALL_KEY, StringUtil.EMPTY_STRING);
			statusMap.put(DROPDOWN_ALL_KEY, StringUtil.EMPTY_STRING);
			priorityMap.put(DROPDOWN_ALL_KEY, StringUtil.EMPTY_STRING);
			assignerMap.put(DROPDOWN_ALL_KEY, StringUtil.EMPTY_STRING);
			handlerMap.put(DROPDOWN_ALL_KEY, StringUtil.EMPTY_STRING);
			categroyMap.put(DROPDOWN_ALL_KEY, StringUtil.EMPTY_STRING);
		}else{
			moduleMap.put(DROPDOWN_ALL_KEY, DROPDOWN_ALL_VALUE);
			programMap.put(DROPDOWN_ALL_KEY, DROPDOWN_ALL_VALUE);
			statusMap.put(DROPDOWN_ALL_KEY, DROPDOWN_ALL_VALUE);
			priorityMap.put(DROPDOWN_ALL_KEY, DROPDOWN_ALL_VALUE);
			assignerMap.put(DROPDOWN_ALL_KEY, DROPDOWN_ALL_VALUE);
			handlerMap.put(DROPDOWN_ALL_KEY, DROPDOWN_ALL_VALUE);
			categroyMap.put(DROPDOWN_ALL_KEY, DROPDOWN_ALL_VALUE);
		}
		req.setAttribute(STR_MODULEMAP, moduleMap);
		req.setAttribute(STR_PROGRAMMAP, programMap);
		req.setAttribute(STR_STATUSMAP, statusMap);
		req.setAttribute(STR_PRIORITYMAP, priorityMap);
		req.setAttribute(STR_ASSIGNERMAP, assignerMap);
		req.setAttribute(STR_HANDLERMAP, handlerMap);
		req.setAttribute(STR_CATEGROYMAP, categroyMap);
	}
	
	public static void setDealBugMap(HttpServletRequest req){
		statusMap.remove(DROPDOWN_ALL_KEY);
		req.setAttribute(STR_STATUSMAP, BugStatus.getProcessStatus());
		handlerMap.remove(DROPDOWN_ALL_KEY);
		req.setAttribute(STR_HANDLERMAP, handlerMap);
		assignerMap.remove(DROPDOWN_ALL_KEY);
		req.setAttribute(STR_ASSIGNERMAP, assignerMap);
		req.setAttribute(STR_DEALRESULTMAP, BugDealResult.resultMap);
	}
	
}
